package controllers;

import play.mvc.*;
import models.*;

public class Security extends Secure.Security {

	static boolean authenticate(String email, String password) {
        User user = User.find("byEmail", email).first();
        return user != null && user.checkPassword(password);
    }
	
	public static boolean connectedUserIsAdmin() {
        User user = User.find("byEmail", connected()).first();
        return user.isAdmin;
    }
	
	public static boolean connectedUserIsExpert() {
        User user = User.find("byEmail", connected()).first();
        return user.isExpert;
    }
	
	public static boolean connectedUserIsPremium() {
        User user = User.find("byEmail", connected()).first();
        return user.isPremium;
    }
	
	static void onDisconnected() {       
		Application.index();
	}
	
	static void onAuthenticated() {
		Courses.index();
    }
	
	public static User getConnected() {
		return User.find("byEmail", Security.connected()).first();
	}

}
